//
//  MainPageViewController.m
//  Utils
//
//  Created by enghou on 2018/4/12.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "MainPageViewController.h"
#import "NetWorkerManager.h"
#import "MailBoxViewController.h"
#import "ProblemsHandlingViewController.h"
#import "ChooseAddressViewController.h"
#import "AppealViewController.h"
@interface MainPageViewController ()
//户籍人口数
@property (weak, nonatomic) IBOutlet UILabel *peopleLabel;

//流动人口数
@property (weak, nonatomic) IBOutlet UILabel *flidPeople;

//常住人口数
@property (weak, nonatomic) IBOutlet UILabel *persistentPeople;

//实有房屋
@property (weak, nonatomic) IBOutlet UILabel *realHouse;

//出租房
@property (weak, nonatomic) IBOutlet UILabel *ownedPeople;

//矛盾纠纷数量
@property (weak, nonatomic) IBOutlet UILabel *problemRemaining;

//矛盾纠纷已办结
@property (weak, nonatomic) IBOutlet UILabel *doneProblem;

//正在办理的矛盾纠纷数量
@property (weak, nonatomic) IBOutlet UILabel *doing;

//待办诉求数量
@property (weak, nonatomic) IBOutlet UILabel *appealRemaining;

//正在办理的诉求数量
@property (weak, nonatomic) IBOutlet UILabel *doingAppeal;

//已办结的诉求服务
@property (weak, nonatomic) IBOutlet UILabel *doneAppeal;

@property(nonatomic,copy)NSString *orgCode;
@end

@implementation MainPageViewController

- (IBAction)lookForRemainingProblem:(id)sender {
    ProblemsHandlingViewController *problem = [[ProblemsHandlingViewController alloc]init];
    problem.modelClsName = @"ProblemHandlingItemModel";
    problem.cellClass = @"ProblemHandlingCell";
    problem.type = 0;
    problem.hidesBottomBarWhenPushed = YES;
    [self push:problem];
}

- (IBAction)lookForDoingProblem:(id)sender {
    ProblemsHandlingViewController *problem = [[ProblemsHandlingViewController alloc]init];
    problem.modelClsName = @"ProblemHandlingItemModel";
    problem.cellClass = @"ProblemHandlingCell";
    problem.type = 1;
    problem.hidesBottomBarWhenPushed = YES;
    [self push:problem];
}

- (IBAction)lookForDoneProblem:(id)sender {
    ProblemsHandlingViewController *problem = [[ProblemsHandlingViewController alloc]init];
    problem.modelClsName = @"ProblemHandlingItemModel";
    problem.cellClass = @"ProblemHandlingCell";
    problem.type = 2;
    problem.hidesBottomBarWhenPushed = YES;
    [self push:problem];
}

- (IBAction)lookForRemainingAppeal:(id)sender {
    AppealViewController *appeal = [[AppealViewController alloc]init];
    appeal.type = 0;
    appeal.hidesBottomBarWhenPushed = YES;
    [self push:appeal];
}

- (IBAction)lookForDoingAppeal:(id)sender {
    AppealViewController *appeal = [[AppealViewController alloc]init];
    appeal.type = 1;
    appeal.hidesBottomBarWhenPushed = YES;
    [self push:appeal];
}
- (IBAction)lookForDoneAppeal:(id)sender {
    AppealViewController *appeal = [[AppealViewController alloc]init];
    appeal.type = 2;
    appeal.hidesBottomBarWhenPushed = YES;
    [self push:appeal];
}

- (IBAction)lookAreas:(id)sender {
    ChooseAddressViewController *choose = [[ChooseAddressViewController alloc]init];
    choose.isMainPage = YES;
    choose.theDelete = self;
    choose.hidesBottomBarWhenPushed = YES;
    [self push:choose];
}

- (IBAction)catMessage:(id)sender {
    MailBoxViewController *mail = [[MailBoxViewController alloc]init];
    mail.hidesBottomBarWhenPushed = YES;
    [self push:mail];
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
//    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
}

-(void)loadData{
    [[NetWorkerManager sharedInstance]getStasticInfoWithUid:self.orgCode successBlock:^(BaseModel *model) {
        [self endLoading];
        if (model.success) {
            NSDictionary *data = [model.data objectForKey:@"data"];
            NSString *householdPopulation = [NSString stringWithFormat:@"%i",[[data objectForKey:@"householdPopulation"]intValue]];
            self.peopleLabel.text = householdPopulation;
            NSString *floatingPopulation = [NSString stringWithFormat:@"%i",[[data objectForKey:@"floatingPopulation"]intValue]];
            self.flidPeople.text = floatingPopulation;
            NSString *residentPopulation = [NSString stringWithFormat:@"%i",[[data objectForKey:@"residentPopulation"]intValue]];
            self.persistentPeople.text = residentPopulation;
            NSString *actualHouse = [NSString stringWithFormat:@"%i",[[data objectForKey:@"actualHouse"]intValue]];
            self.realHouse.text = actualHouse;
            NSString *rentalHouse = [NSString stringWithFormat:@"%i",[[data objectForKey:@"rentalHouse"]intValue]];
            self.ownedPeople.text = rentalHouse;
            NSString *issues_needDo = [NSString stringWithFormat:@"%i",[[data objectForKey:@"issues_needDo"]intValue]];
            self.problemRemaining.text = issues_needDo;
            NSString *issues_done = [NSString stringWithFormat:@"%i",[[data objectForKey:@"issues_done"]intValue]];
            self.doing.text = issues_done;
            NSString *issues_completed = [NSString stringWithFormat:@"%i",[[data objectForKey:@"issues_completed"]intValue]];
            self.doneProblem.text = issues_completed;
            NSString *appeal_needDo =[NSString stringWithFormat:@"%i",[[data objectForKey:@"appeal_needDo"]intValue]];
            self.appealRemaining.text = appeal_needDo;
            NSString *appeal_done = [NSString stringWithFormat:@"%i",[[data objectForKey:@"appeal_done"]intValue]];
            self.doingAppeal.text = appeal_done;
            NSString *appeal_completed = [NSString stringWithFormat:@"%i",[[data objectForKey:@"appeal_completed"]intValue]];
            self.doneAppeal.text = appeal_completed;
        }else{
            [self commonFailBlockWithModel:model];
        }
    } failBlock:^(NSInteger code) {
        [self endLoading];
        [self alertSome:kNetWorkFail];
    }];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadData];
}

-(void)fetchModel:(id)model{
    self.orgCode = model;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
